﻿Public Class FormEmpleadosListado

    Dim classController As New Class_RC_Controller.rc_Empleados()

    Private m_frmEmpleados As FrmEmpleados
    Public Property frmEmpleados() As FrmEmpleados
        Get
            Return m_frmEmpleados
        End Get
        Set(ByVal value As FrmEmpleados)
            m_frmEmpleados = value
        End Set
    End Property

   

    Private Sub CargarEmpleados()

        Dim codTipoEmpleado As Integer
        If cbxTipoEmpleado.Checked Then
            codTipoEmpleado = cboTipoEmpleado.SelectedValue
        End If

        Dim codCategoria As Integer
        If cbxCategoria.Checked Then
            codCategoria = cboCategoria.SelectedValue
        End If

        Dim dt As New DataTable
        dt = classController.get_Empleados_All(oiml.dbConn, 0, txtNombre.Text, txtApellido.Text, 0, codTipoEmpleado, codCategoria)
        dgEmpleado.DataSource = dt

    End Sub

    Private Sub CargarCombos()
        Dim dsTipo As New DataTable
        dsTipo = classController.get_tipo_Empleado(oiml.dbConn)
        If Not dsTipo Is Nothing Then
            If dsTipo.Rows.Count > 0 Then
                cboTipoEmpleado.DataSource = dsTipo
                cboTipoEmpleado.DisplayMember = "DescTipoEmp"
                cboTipoEmpleado.ValueMember = "codTipoEmp"
            End If
        End If

        Dim dsCategoria As New DataTable
        dsCategoria = classController.get_Categoria(oiml.dbConn, 0)
        If Not dsCategoria Is Nothing Then
            If dsCategoria.Rows.Count > 0 Then
                cboCategoria.DataSource = dsCategoria
                cboCategoria.DisplayMember = "DescCategoria"
                cboCategoria.ValueMember = "CodCategoria"
            End If
        End If
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgEmpleado.SelectedRows.Count > 0 Then
                Dim cod As New Integer
                cod = dgEmpleado.SelectedRows(0).Cells(0).Value

                If frmEmpleados Is Nothing Then

                    frmEmpleados = New FrmEmpleados
                    frmEmpleados.codemp = cod

                    'If frmClientes.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmEmpleados.ShowDialog()
                    CargarEmpleados()
                    frmEmpleados.Dispose()
                    frmEmpleados = Nothing
                    'End If
                Else
                    frmEmpleados.codemp = cod
                    frmEmpleados.ShowDialog()
                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        CargarEmpleados()
    End Sub

    Private Sub txtNombre_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNombre.KeyDown, txtApellido.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarEmpleados()

        End If
    End Sub

    Private Sub dgEmpleado_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgEmpleado.DoubleClick
        btnEditar_Click(sender, e)
    End Sub

    Private Sub dgClientes_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgEmpleado.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If

    End Sub

    Private Sub cbxTipoCliente_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cbxTipoEmpleado.KeyDown, cbxCategoria.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarEmpleados()
        End If
    End Sub

    Private Sub cboTipoCliente_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboTipoEmpleado.KeyDown, cboCategoria.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarEmpleados()
        End If
    End Sub

    Private Sub FormEmpleadosListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgEmpleado.AutoGenerateColumns = False
        CargarCombos()
        CargarEmpleados()
    End Sub

    
    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        '    If frmciudad Is Nothing Then
        frmEmpleados = New FrmEmpleados()
        frmEmpleados.ShowDialog()
        CargarEmpleados()
    End Sub
End Class